package itsur.arquitecturas.implicitinvocation;

/**************************************************************************************
** Class name: CourseList	
** Author: A.J. Lattanze
** Date: 12/29/99
** Version 1.0
***************************************************************************************
** Purpose: Assignment 3 for CS 15-675, Architectures for Software Systems. This class
** is used by various other classes that need to keep a list of courses on hand.  This
** class extends the List class which provides the basic functionality for storage and
** retrieval of the Course Object from the list.
** (reused from assignment 2)
**
** Abstract: The CourseList class provides the following methods:
**
**	void AddCourse( Course Obj ) - Adds a new course to the list. All the issues 
**	of casting are taken care of within this class.
**
**	boolean FindCourse( Course Obj ) - Determines whether the course is currently
**	in the list.  If the course is in the list, a true is returned, otherwise
**	a false boolean value is returned.
** 
**	Course Obj = GetNextCourse() - Returns the course pointed at the current 
**	position pointed to by the internal list pointer of the internal list. Subsequent 
**	calls will return the next Course object in the list.  A null object is returned
**	if list is empty or the end of list has been reached.
**
**	public Course FindCourseByID( String CourseID ) - Finds a Course in a list
** 	using the CourseID as the search key.  If the current Course object is returned 
**	to the caller.  If there is no match, null is returned to the caller.
**
** Modification Log
**************************************************************************************
**
**************************************************************************************/

class CourseList extends List
{
	CourseList()
	{
		super();

	} // Constructor

	public void AddCourse( Course CourseObject )
	{
		AppendItemToList( (Object) CourseObject );

	} // AddCourse


	public Course GetNextCourse()
	{
		return (Course) GetItemFromList();

	} // GetNextCourse

	public boolean FindCourse( Course CourseObject )
	{
		Course CurrentObject;
		boolean Done = false;
		boolean Result = false;

		// Note that this method assumes that all courses have different
		// identification numbers.

		GoToFrontOfList();
		
		while (!Done )
		{
		   CurrentObject = GetNextCourse();
			
		   if ( CurrentObject == null )
		   {
			Done = true;

		   } else {
		 	if ( CourseObject.CourseID.compareToIgnoreCase( CurrentObject.CourseID ) == 0 )
			{
		 	   Result = true;

			} // if
		   } // if
		} // while

		return( Result );

	} // FindCourse


	public Course FindCourseByIDAndSection( String CourseID, String Section )
	{
		Course CurrentObject = null;
		boolean Done = false;
		boolean Found = false;

		// Note that this method assumes that all courses have different
		// identification numbers.

		GoToFrontOfList();
		
		while (!Done )
		{
		   CurrentObject = GetNextCourse();
			
		   if ( CurrentObject == null )
		   {
			Done = true;

		   } else {
		 	if (( CurrentObject.CourseID.compareToIgnoreCase( CourseID ) == 0 ) &&
			    ( CurrentObject.Section.compareToIgnoreCase( Section ) == 0 ))
			{
		 	   Found = true;
			   Done = true;

			} // if
		   } // if
		} // while

		if ( Found )
		{ 
			return( CurrentObject );

		} else {

			return( null );

		} // if 

	} // FindCourseByIDAndSection

} // CourseList